package com.itheima.ydd.controller;

import com.itheima.ydd.entity.Result;
import com.itheima.ydd.entity.YddArticle;
import com.itheima.ydd.service.YddArticleService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

@RestController
@Slf4j
@RequestMapping("/ydd_article")
public class YddArticleController {
    @Autowired
    private YddArticleService yddArticleService;

    /**
     * 分页查询文章与模糊查询功能实现
     * @param startTime
     * @param endTime
     * @param title
     * @param cateid
     * @param page
     * @param limit
     * @return
     */
    @GetMapping("/list")
    public ResponseEntity<Result> findAll(@RequestParam("start_time") String startTime, @RequestParam("end_time") String endTime, String title, String cateid, Integer page, Integer limit) {
        return yddArticleService.findPages(startTime, endTime, title, cateid, page, limit);
    }

    /**
     * 根据id删除文章
     * @param id
     * @return
     */
    @GetMapping("/del")
    public ResponseEntity<Result> delete(Integer id){
        return yddArticleService.deleteById(id);
    }

    /**
     * 添加文章功能
     * @param yddArticle
     * @return
     */
    @PostMapping("/add")
    public ResponseEntity<Result> add(@RequestBody YddArticle yddArticle){
        return yddArticleService.add(yddArticle);
    }

    /**
     * 根据id获取文章信息
     * @param id
     * @return
     */
    @GetMapping("/rowInfo")
    public ResponseEntity<Result> selectById(Integer id){
        return yddArticleService.selectById(id);
    }

    /**
     * 修改文章信息
     * @return
     */
    @PostMapping("/update")
    public ResponseEntity<Result> updateArticle(@RequestBody YddArticle yddArticle){
        return yddArticleService.updateArticle(yddArticle);
    }
}
